/*
* jlb
*/
package com.jlb.item.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.item.entity.ItemOrder;
import com.jlb.item.service.ItemOrderSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 订单 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/itemOrder")
@Slf4j
@Api(value = "订单控制器", description = "订单控制器")
public class ItemOrderCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private ItemOrderSV itemOrderSV;

    /**
     * 查询ItemOrder一个详情信息
     *
     * @param id
     * @param code     编码
     * @param userCode 用户编码
     * @param itemCode 产品编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ItemOrder一个详情信息", notes = "查询ItemOrder一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "itemCode", value = "产品编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(Long id, String code, String userCode, String itemCode) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        if (userCode == null) {
            return null;
        }
        if (itemCode == null) {
            return null;
        }
        ItemOrder itemOrder = itemOrderSV.load(id, code, userCode, itemCode);
        log.info(JSON.toJSONString(itemOrder));
        return BeanRet.create(true, "查询成功", itemOrder);
    }


    /**
     * 根据条件id查询ItemOrder一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询ItemOrder一个详情信息", notes = "查询ItemOrder一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable Long id) {
        if (id == null) {
            return null;
        }
        ItemOrder itemOrder = itemOrderSV.loadById(id);
        log.info(JSON.toJSONString(itemOrder));
        return BeanRet.create(true, "查询成功", itemOrder);
    }

    /**
     * 根据条件code查询ItemOrder一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ItemOrder一个详情信息", notes = "查询ItemOrder一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable String code) {
        if (code == null) {
            return null;
        }
        ItemOrder itemOrder = itemOrderSV.loadByCode(code);
        log.info(JSON.toJSONString(itemOrder));
        return BeanRet.create(true, "查询成功", itemOrder);
    }

    /**
     * 根据条件userCode查询ItemOrder一个详情信息
     *
     * @param userCode 用户编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ItemOrder一个详情信息", notes = "查询ItemOrder一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "用户编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/userCode/{userCode}")
    @ResponseBody
    public BeanRet loadByUserCode(@PathVariable String userCode) {
        if (userCode == null) {
            return null;
        }
        ItemOrder itemOrder = itemOrderSV.loadByUserCode(userCode);
        log.info(JSON.toJSONString(itemOrder));
        return BeanRet.create(true, "查询成功", itemOrder);
    }

    /**
     * 根据条件itemCode查询ItemOrder一个详情信息
     *
     * @param itemCode 产品编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询ItemOrder一个详情信息", notes = "查询ItemOrder一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemCode", value = "产品编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/itemCode/{itemCode}")
    @ResponseBody
    public BeanRet loadByItemCode(@PathVariable String itemCode) {
        if (itemCode == null) {
            return null;
        }
        ItemOrder itemOrder = itemOrderSV.loadByItemCode(itemCode);
        log.info(JSON.toJSONString(itemOrder));
        return BeanRet.create(true, "查询成功", itemOrder);
    }


    /**
     * 查询ItemOrder信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ItemOrder信息集合", notes = "查询ItemOrder信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTimeBegin", value = "更新时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTimeEnd", value = "更新时间", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore ItemOrder itemOrder, Integer curPage, Integer pageSize) {
        Page<ItemOrder> page = new Page<ItemOrder>(pageSize, curPage);
        List<ItemOrder> itemOrders = itemOrderSV.list(itemOrder, page.genRowStart(), page.getPageSize());
        page.setVoList(itemOrders);
        int total = itemOrderSV.count(itemOrder);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询ItemOrder信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询ItemOrder信息集合", notes = "查询ItemOrder信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "itemCode", value = "产品编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(Long id, String code, String userCode, String itemCode, Integer curPage, Integer pageSize) {
        Page<ItemOrder> page = new Page<ItemOrder>(pageSize, curPage);
        List<ItemOrder> itemOrders = itemOrderSV.list(id, code, userCode, itemCode, page.genRowStart(), page.getPageSize());
        page.setVoList(itemOrders);
        int total = itemOrderSV.count(id, code, userCode, itemCode);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计ItemOrder信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计ItemOrder信息数量根据主键", notes = " 统计ItemOrder信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "itemCode", value = "产品编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id, String code, String userCode, String itemCode) {
        return itemOrderSV.count(id, code, userCode, itemCode);
    }

    /**
     * 统计ItemOrder信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计ItemOrder信息数量", notes = "统计ItemOrder信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "itemCode", value = "产品编码", paramType = "query"),
            @ApiImplicitParam(name = "itemName", value = "产品名称", paramType = "query"),
            @ApiImplicitParam(name = "itemNum", value = "产品数量", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：:待支付 Pay，待发货 Deliver，已发货 Shipped，已签收 Signed", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "联系人", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "地址", paramType = "query"),
            @ApiImplicitParam(name = "cash", value = "现金价格", paramType = "query"),
            @ApiImplicitParam(name = "jlb", value = "金兰宝价格", paramType = "query"),
            @ApiImplicitParam(name = "ore", value = "矿石价格", paramType = "query"),
            @ApiImplicitParam(name = "active", value = "激活币价格", paramType = "query"),
            @ApiImplicitParam(name = "payMethod", value = "支付方式", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "电话", paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "留言", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore ItemOrder itemOrder) {
        if (itemOrder == null) {
            return itemOrderSV.count(new HashMap());
        } else {
            return itemOrderSV.count(itemOrder);
        }
    }


    /**
     * 创建ItemOrder
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建ItemOrder", notes = "创建ItemOrder")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemName", value = "产品名称", paramType = "query"),
            @ApiImplicitParam(name = "itemNum", value = "产品数量", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：:待支付 Pay，待发货 Deliver，已发货 Shipped，已签收 Signed", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "联系人", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "地址", paramType = "query"),
            @ApiImplicitParam(name = "cash", value = "现金价格", paramType = "query"),
            @ApiImplicitParam(name = "jlb", value = "金兰宝价格", paramType = "query"),
            @ApiImplicitParam(name = "ore", value = "矿石价格", paramType = "query"),
            @ApiImplicitParam(name = "active", value = "激活币价格", paramType = "query"),
            @ApiImplicitParam(name = "payMethod", value = "支付方式", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "电话", paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "留言", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore ItemOrder itemOrder) {
        itemOrderSV.save(itemOrder);
        return BeanRet.create(true, "创建成功", itemOrder);
    }


    /**
     * 修改ItemOrder
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改ItemOrder", notes = "修改ItemOrder")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "itemCode", value = "产品编码", paramType = "query"),
            @ApiImplicitParam(name = "itemName", value = "产品名称", paramType = "query"),
            @ApiImplicitParam(name = "itemNum", value = "产品数量", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：待支付 Pay，待发货 Deliver，已发货 Shipped，已签收 Signed", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "联系人", paramType = "query"),
            @ApiImplicitParam(name = "address", value = "地址", paramType = "query"),
            @ApiImplicitParam(name = "cash", value = "现金价格", paramType = "query"),
            @ApiImplicitParam(name = "jlb", value = "金兰宝价格", paramType = "query"),
            @ApiImplicitParam(name = "ore", value = "矿石价格", paramType = "query"),
            @ApiImplicitParam(name = "active", value = "激活币价格", paramType = "query"),
            @ApiImplicitParam(name = "payMethod", value = "支付方式", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "电话", paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "留言", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore ItemOrder itemOrder) {
        itemOrderSV.modify(itemOrder);
        return BeanRet.create(true, "修改成功", itemOrder);
    }

    /**
     * 删除ItemOrder
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除ItemOrder", notes = "删除ItemOrder")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "itemCode", value = "产品编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String code, String userCode, String itemCode) {
        itemOrderSV.delete(id, code, userCode, itemCode);
        return BeanRet.create(true, "删除ItemOrder成功");
    }

}
